import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Color;
import java.awt.Font;
import java.sql.SQLException;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;


public class Eingeloggt extends JDialog implements ActionListener {

	private final JPanel contentPanel = new JPanel();
	MyKeyListener ks = new MyKeyListener();
	private JLabel lblDerLoginWar;
	private Database db;
	private User user;

	/**
	 * Launch the application.
	 */

	/**
	 * Create the dialog.
	 */
	public Eingeloggt(Database db, User user) {
		
		this.db=db;
		this.user=user;
		setBounds(100, 100, 449, 205);
		setVisible(true);
		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
	    int x = (d.width - getSize().width) / 2;
	    int y = (d.height - getSize().height) / 2;
	    setLocation(x, y);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		{
			lblDerLoginWar = new JLabel("Hallo " + user.getVorname() + ", Ihr Login war ");
			lblDerLoginWar.setFont(new Font("Verdana", Font.PLAIN, 16));
		}
		
		JLabel lblErfolg = new JLabel("erfolgreich");
		lblErfolg.setForeground(new Color(0, 204, 0));
		lblErfolg.setFont(new Font("Verdana", Font.BOLD, 16));
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(5)
					.addComponent(lblDerLoginWar)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(lblErfolg)
					.addContainerGap(113, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(41)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblErfolg)
						.addComponent(lblDerLoginWar))
					.addContainerGap(58, Short.MAX_VALUE))
		);
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(new Color(51, 153, 204));
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setFont(new Font("Verdana", Font.PLAIN, 14));
				okButton.setActionCommand("OK");
				okButton.addActionListener(this);
				okButton.addKeyListener(ks);
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if (arg0.getActionCommand()=="OK"){
			dispose();
		    try {
				new Kinoverwaltung(db, user);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	class MyKeyListener extends KeyAdapter implements KeyListener {
		String keyString;
		int keyCode;

		public void keyPressed(KeyEvent e) {
			int id = e.getID();

			if (id == KeyEvent.KEY_TYPED) {
				char c = e.getKeyChar();
				keyString = "key character = '" + c + "'";
			} else {
				keyCode = e.getKeyCode();
				keyString = "key code = " + keyCode + " ("
						+ KeyEvent.getKeyText(keyCode) + ")";
			}

			if (keyCode == 10){
			dispose();
			try {
				new Kinoverwaltung(db, user);
			} catch (SQLException ex) {
				// TODO Auto-generated catch block
				ex.printStackTrace();
			}
		
		

		}
	}
	}
}

